package com.bh.controller;

import com.bh.domain.CommonResult;
import com.bh.domain.ResultCode;
import com.bh.domain.User;
import com.bh.mapper.UserMapper;
import com.bh.service.IUserService;
import com.sun.net.httpserver.Authenticator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author86151
 * @date2022/10/24
 * @apiNote
 */
@RestController
@RequestMapping("/recruit")
public class UserController {
    @Autowired
    private IUserService userService;

    @PostMapping("/login")
    public CommonResult<?> login(User user) {

        User userResult = userService.selectOneUser(user);
        if (userResult != null){
            return new CommonResult(ResultCode.SUCCESS,"登陆成功");
        }
        return new CommonResult(ResultCode.ERROR,"用户名密码错误");
    }

    @GetMapping("/logout")
    public CommonResult<?> logout(HttpServletRequest request) {
        request.getSession().removeAttribute("user");
        return new CommonResult(ResultCode.SUCCESS,"退出成功");
    }
}
